package branchingAlgorithm;

public class TowerOfHanoi {
    public static void main(String[] args) {
        hanoi(65, 'A', 'B', 'C');

    }

    /**
     * 汉诺塔问题
     *
     * @param num
     * @param a   初始的柱子
     * @param b   暂存的柱子
     * @param c   最终的柱子
     */
    public static void hanoi(int num, char a, char b, char c) {
        if (num == 1) {
            System.out.println("将" + num + "从" + a + "移动到" + c);
        } else {
            //采用分治策略
            //先把上面的从a通过c挪到b
            hanoi(num - 1, a, c, b);
            System.out.println("将" + num + "从" + a + "移动到" + c);
            hanoi(num - 1, b, a, c);
        }

    }
}
